package com.david.dubbo.filter;


import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * @author David
 * @version V1.0
 * @Package com.david.dubbo.filter
 * @date 2021/4/12 22:42
 */
//作用指定消费者和生产者
@Activate(group = {CommonConstants.CONSUMER,CommonConstants.PROVIDER})
public class TimeFilter implements Filter {

    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {

        long t1 = System.currentTimeMillis();
        try {
            URL url = invoker.getUrl();
            System.out.println("url.getServiceName() = " + url.getServiceName());
            String serviceName = invocation.getServiceName();
            System.out.println("serviceName = " + serviceName);
            Result result = invoker.invoke(invocation);
            return result;
        }finally {
            long t2 = System.currentTimeMillis();
            System.out.println("请求耗时" + (t2-t1));
        }

    }
}
